package cn.lhl.service.impl;

import cn.lhl.dao.cargo.FactoryDao;
import cn.lhl.domain.cargo.Factory;
import cn.lhl.domain.cargo.FactoryExample;
import cn.lhl.service.FactoryManagerService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class FactoryManagerServiceImpl implements FactoryManagerService {

    //注入dao
    @Autowired
    private FactoryDao factoryDao;

    //实现分页功能的厂家列表
    public PageInfo findAll(FactoryExample factoryExample, int page, int size) {
        //PageHlper
        PageHelper.startPage(page,size);
        //以下的查询语句将会分页
        List<Factory> factories = factoryDao.selectByExample(factoryExample);
        return new PageInfo(factories);
    }

    //对厂家信息进行删除操作
    public void delete(String id) {
        factoryDao.deleteByPrimaryKey(id);
    }

    //增加厂家信息
    public void add(Factory factory) {
        factoryDao.insertSelective(factory);
    }

    public Factory findById(String id) {
        Factory factory = factoryDao.selectByPrimaryKey(id);
        return factory;
    }

    public void update(Factory factory) {
        factoryDao.updateByPrimaryKeySelective(factory);
    }


}
